package org.lex.ftp.util.prefs;

import java.nio.charset.Charset;

import org.lex.app.prefs.MemoryResourceMap;
import org.lex.app.prefs.ResourceHelper;
import org.lex.app.prefs.ResourceMap;
import org.lex.utils.SystemProperties;


public class DefaultConfiguration {
	public static void loadDefaultConfiguration(ResourceMap rm) {
		// construct defaults
		ResourceMap defaults = new MemoryResourceMap();
		DefaultConfiguration.loadDefaultFileExistRules(defaults);
		defaults.putProperty(Keys.DOWNLOAD_PATH, SystemProperties.userHome());
		// ===========================================================
		defaults.putProperty(Keys.CONNECT_TIMEOUT, "60000");
		defaults.putProperty(Keys.CONNECT_RETRY_ENABLED, "true");
		defaults.putProperty(Keys.CONNECT_RETRY_DELAY, "18000");
		defaults.putProperty(Keys.CONNECT_RETRY_COUNT, "9999");
		defaults.putString(Keys.SERVER_CHARSET, Charset.defaultCharset().name());
		// ===================================================================
		defaults.putProperty(Keys.KEEP_ALIVE_ENABLED, "true");
		defaults.putProperty(Keys.KEEP_ALIVE_COMMAND, "noop");
		defaults.putProperty(Keys.KEEP_ALIVE_DELAY, "20000");
		// ============================================================
		defaults.putProperty(Keys.TRANSFER_MODE, "auto");
		defaults.putProperty(Keys.ASCIIFiles, "c,cpp,cs,h,hpp,java,txt,log");
		// =============================================================
		defaults.putProperty(Keys.SOUND_ENABLED, "true");
		defaults.putProperty(Keys.SOUND_CONNECT, "/lex/ftp/resources/sound/connect.wav");
		defaults.putProperty(Keys.SOUND_DISCONNECT, "/lex/ftp/resources/sound/notify.wav");
		defaults.putProperty(Keys.SOUND_COMPLETE, "/lex/ftp/resources/sound/complete.wav");
		defaults.putProperty(Keys.SOUND_ERROR, "/lex/ftp/resources/sound/error.wav");
		// load defaults
		ResourceHelper.addAll(defaults, rm, false);
	}

	public static void loadDefaultFileExistRules(ResourceMap c) {
		StringBuilder buf = new StringBuilder();
		String def = FileActions.DEFAULT_ACTION.name();
		for (int i = 0; i < 8; i++)
			buf.append(def).append(',');
		buf.append(def);
		c.putProperty(Keys.EXIST_RULES, buf.toString());
	}

	private DefaultConfiguration() {
	}
}
